package org.custom.spring.boot.security.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.custom.spring.boot.entity.Result;
import org.custom.spring.boot.security.entity.Login;
import org.custom.spring.boot.security.service.ApproveService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.validation.constraints.NotNull;

/**
 * 系统认证相关网络接口
 *
 * @author LiKun
 * @date 2021/11/8
 */
@RestController
@RequestMapping("/approve")
@Api(tags = "系统认证相关网络接口")
public class ApproveController {
    @Resource
    private ApproveService approveService;

    @PostMapping("/login")
    @ApiOperation(value = "系统用户登录接口")
    public Result<String> login(@RequestBody @NotNull(message = "账户信息不能为空") Login login,
                                ServletRequest request) throws JsonProcessingException {
        return Result.success(approveService.login(login, request.getRemoteAddr()));
    }
}
